<template>
  <div class="org-modify-wrap">
    <el-dialog :visible.sync="dialogVisible_dep.show" center>
      <!-- <div class="show-title">分组ID：{{ org_id }}</div>
      <div class="show-title">分组名称：{{ org_name_check }}</div> -->
      <div class="center">
        <el-form :inline="true" :model="ruleform" ref="form" :rules="rules">
          <el-form-item label="所属部门" prop="department">
            <el-input v-model="ruleform.department" placeholder></el-input>
          </el-form-item>
          <br />
          <el-form-item>
            <el-button type="primary" size="small" @click="submitModify('form')"
              >设置</el-button
            >
            <el-button
              type="warning"
              size="small"
              plain
              @click="onReset('form')"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getData, postData } from "@/request/http";

export default {
  name: "modifyDep",
  props: {
    batchDelectId: {
      type: Array,
      default: "",
    },
    dialogVisible_dep: {
      type: Object,
      default() {
        return {
          show: false,
        };
      },
    },
  },
  data() {
    return {
      // org_id_check: "",
      // org_name_check: "",
      ruleform: {
        department: "",
      },
      rules: {
        department: [{ required: true, message: "", trigger: "blur" }],
      },
    };
  },
  watch: {},
  methods: {
    //修改 提交
    submitModify(formName) {
      var that = this;
      that.$refs[formName].validate((valid) => {
        if (valid) {
          postData("/adminweb/device/update/department", {
            devices: that.batchDelectId,
            department: that.ruleform.department,
          })
            .then((res) => {
              if (res.code == 0) {
                that.$message.success("设置成功！");
                that.$emit("refreshList");
              } else if (res.code == -56055) {
                return;
              } else {
                that.$message.error(res.code + "，" + res.msg);
              }
            })
            .catch((res) => {
              that.$message.error(res.code + "，" + res.msg);
            });
        } else {
          that.$message.error("设置失败");
          return false;
        }
      });
    },
    // 重置
    onReset(val) {
      //this.$emit("reset", true);
      this.$refs[val].resetFields();
    },
  },
};
</script>

<style scoped>
.center {
  margin-top: 30px;
  width: 100%;
  height: 400px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.show-title {
  height: 30px;
  line-height: 30px;
  font-weight: 600;
  color: #676a6d;
}

.org-modify-wrap >>> .el-dialog {
  width: 40%;
}
</style>
